package jass.iss.edu.Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.*;


//DAO


import jass.iss.edu.Properties.*;

//Screens
import jass.iss.edu.Screen.*;


public class JobAdvertisementController implements MouseListener, ActionListener{
	
	//ALL DAO
	JobAdvertisementDAO advertDAO;
	CompanyDAO compDAO;
	DepartmentDAO deptDAO;
	GeographyDAO geoDAO;
	
	//Screen Objects
	private JobAdvertiserHomeScreen JobAdvertiserHomeScreen;
	private JobAdvertisementListScreen frmJobAdvertListScreen;
	private ModifyJobAdvertisementScreen frmModifyJobAdvertisementScreen;
	//ActionListener
	private ActionListener al;
	
	private void showJobAdvertisementList(){
		frmJobAdvertListScreen = new JobAdvertisementListScreen(this);
		frmJobAdvertListScreen.setVisible(true);		
	}
	
	
	private void showModifyJobAdvertisementScreen(String pAdvertID){
		frmModifyJobAdvertisementScreen = new ModifyJobAdvertisementScreen(pAdvertID, this);
		frmModifyJobAdvertisementScreen.setVisible(true);		
	}
	
	
	public JobAdvertisementController() {
		
		JobAdvertiserHomeScreen = new JobAdvertiserHomeScreen(this);
		try {
			advertDAO = new JobAdvertisementDAO();
			compDAO = new CompanyDAO();
			deptDAO = new DepartmentDAO();
			geoDAO = new GeographyDAO();
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void manageJobAdvertisement() {
		
	}
	
	public void searchJobAdvertisement() {
		
	}
	
	public void withdrawJobAdvertisement() {
		
		System.out.println("Withdraw Job Advertisement");
		
	}
	
	public void addJobAdvertisement() {
		
		System.out.println("Add Job Advertisement");
		
	}
	
	public void viewJobAdvertisementList() {
	
			
	}

	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		String cmd = e.getActionCommand();
	
       if(cmd.equals("ViewJobReponseList")){
    	   
       }
       else if (cmd.equals("ViewAdvertisementList")){
    	   showJobAdvertisementList();
       }
       
        
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {

		if (e.getClickCount() == 1) {
			 JTable dtbl = frmJobAdvertListScreen.getJTable();	
			 int row=dtbl.rowAtPoint(e.getPoint());
			 int col=dtbl.columnAtPoint(e.getPoint()); 
			
			 //Modify
			 if(col==5){
				 String advertID =dtbl.getValueAt(row,0).toString();
				 this.showModifyJobAdvertisementScreen(advertID);
			 }
			 //Withdraw
			 else if(col==6){
				 int n = JOptionPane.showConfirmDialog(frmJobAdvertListScreen, "Withdraw Advertisement ?");
				 if(n==0)
				 {				
			  		 //set selected advertisement if
					 String advertID =dtbl.getValueAt(row,0).toString();
					 JobAdvertisementDTO advert = (JobAdvertisementDTO) advertDAO.get(advertID);
					 advert.setJobAdvertStatus("Withdraw");
					 advertDAO.set(advert);
					 
				 }
			 }
			 else if(col==7){			 
			 }
			 
			 
			 

		}//end of mouse click handling
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}



}
